home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Failure.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
- #ifndef __FAILUREHANDLER__
- #define __FAILUREHANDLER__
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #include <setjmp.h>
-
- #define ePointerNil -110
- #define eGeneralErr -1
- #define eAssertionFailure -30000
-
- #define kMagicFailID 'fail'
-
- #define kInExceptionHandler 0x001
-
- /*
- // Data types:
- */
- struct FailStack
- {
- struct FailStack* next;
- OSErr error;
- jmp_buf env;
- long magicFailID;
- long flags;
- };
-
- typedef struct FailStack FailStack;
-
- typedef void (*NotifyFailureProc)(void);
-
- /*
- // Prototypes
- */
- void _SetupTry(FailStack* failInfo);
- void _PopFailureStack(void);
- void _Failure( OSErr theErr );
- void _FailOSErr( OSErr theErr );
- OSErr _TheFailError(void);
- void _FailAgain(void);
-
- void SetExceptionNotifyProc(NotifyFailureProc notifyProc);
- Boolean ExceptionNotifyProcInstalled(void);
-
- void * GetExceptionChain ();
- void SetExceptionChain ( void * );
-
- extern const char* GetErrorName ( OSErr error );
-
- /***********************************|****************************************/
-
- /*
- // TRY / EXCEPT / ENDTRY macros
- */
- #undef TRY
- #undef EXCEPTION
- #undef ENDEXCEPTION
- #undef NOHANDLER
- #undef CHECKPOINT
- #undef RETRY
- #undef FAIL
- #undef PASSEXCEPTION
- #undef FAILOSErr
- #undef FAILNULL
- #undef FAILifTRUE
- #undef FAILifFALSE
-
- Boolean BreakOnFailures();
-
- # define TRY { do { FailStack failInfo; _SetupTry(&failInfo); if( setjmp(failInfo.env) == 0 ) {
-
- # define EXCEPTION } else { keith<<"EXCEPTN : #"<<_TheFailError()<<" (" << GetErrorName(_TheFailError()) << ") file "<<__FILE__<<", line "<<__LINE__<<endl;
-
- # define ENDEXCEPTION }; _PopFailureStack(); } while(false); }
-
- # define NOHANDLER }; _PopFailureStack(); } while(false); }
-
- # define CHECKPOINT() { }
-
- # define FAIL(code) { keith << "FAIL : #"<< code <<" (" << GetErrorName ( code ) << ") file "<<__FILE__<<", line "<<__LINE__<<endl; if (BreakOnFailures()) BreakStr ("\pFAILURE");; _FailOSErr(code); }
-
- # define PASSEXCEPTION() { keith<<"PASSEXCP: #"<<EXCEPTIONCODE<<" (" << GetErrorName (EXCEPTIONCODE) << "), file "<<__FILE__<<", line "<<__LINE__<<endl; _FailAgain(); }
-
- # define FAILOSErr(code) { short _FAILCODE=code; if ( _FAILCODE ) { keith << "FAIL/OS : #"<<_FAILCODE<<" (" << GetErrorName ( code ) << "), file "<<__FILE__<<", line "<<__LINE__<<endl; if (BreakOnFailures()) BreakStr ("\pFAILURE");_FailOSErr(_FAILCODE); } }
-
- # define FAILNULL(p) { if (!p) { keith<<"FAILNULL: file "<<__FILE__<<", line "<<__LINE__<<endl; if (BreakOnFailures()) BreakStr ("\pFAILNULL"); _FailOSErr(-108); } }
- # define FAILifTRUE(p) { if (p) { keith<<"FAILTRUE: file "<<__FILE__<<", line "<<__LINE__<<endl; if (BreakOnFailures()) BreakStr ("\pFAILTRUE"); _FailOSErr(-1);} }
- # define FAILifFALSE(p) { if (!p) { keith<<"FAILFALS: file "<<__FILE__<<", line "<<__LINE__<<endl; if (BreakOnFailures()) BreakStr ("\pFAILFALSE"); _FailOSErr(-1);} }
-
- # define FAILIf(cond,error) if (cond) FAIL(error);else
-
- /*
- // Convenience macros
- */
- #define FAILResError() _FailOSErr( ResError() )
- #define FAILMemError() _FailOSErr( MemError() )
-
- #define FAILResErrorOrNil(ptr) do { FailResError(); FAILNil(ptr); } while(false)
- #define FAILMemErrorOrNil(ptr) do { FailMemError(); FailNil(ptr); } while(false)
-
- /*
- // Assertion macros
- */
- #define Assert(truth) if( !(truth) ) FailOSErr( eAssertionFailure )
- #define AssertPtrValid(p) if( (p == nil) || (((long)(p) & 1) != 0) ) FailOSErr( eAssertionFailure )
- #define AssertHandleValid(h) AssertPtrValid(h); AssertPtrValid(*h)
-
- #define EXCEPTIONCODE _TheFailError()
- #endif
-